package pe.org.jhsystem.consola.cola.gestion;

/**
 *
 * @author jhuamanv
 */
public class ColaSincronizada {
    int n;
    boolean bandera = false;

    public synchronized int obten(){
        if(!bandera)
        try{wait();}catch(InterruptedException e){System.out.println("Error: "+e.getCause().toString());};
        System.out.println( "Obtenido: " + n );
        bandera = false;
        notify();
        return n;
    }

    public synchronized void coloca(int paramN){
    if(bandera) try{wait();}catch(InterruptedException e){System.out.println("Error: "+e.getCause().toString());};
    n = paramN;
    bandera =true;
    System.out.println( "Colocado: " + n );
    notify();
    }
}
